﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Yuebon.Framework.Common.Data;
using Yuebon.Framework.Common.Models;

namespace Yuebon.Framework.Common.IServices
{
    public interface IService<T, in TKey>: IDisposable where T:IBaseModel<TKey>
    {
        /// <summary>
        /// 根据条件统计记录数量
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        int Count(Expression<Func<T, bool>> where = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        bool Exists(Expression<Func<T, bool>> where = null);
        bool Exists(Expression<Func<T, bool>> where = null, params Expression<Func<T, object>>[] includes);

        T GetSingle(TKey key);

        T GetSingle(TKey key, params Expression<Func<T, object>>[] includes);

        IList<T> Get(Expression<Func<T, bool>> where = null);
        IList<T> Get(Expression<Func<T, bool>> where = null, params Expression<Func<T, object>>[] includes);

        int Add(T entity);

        int AddRange(ICollection<T> entities);

        int Edit(T entity);

        int EditRange(ICollection<T> entities);

        int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> updateExp);

        int Update(T model, params string[] updateColumns);

        int Delete(TKey key);

        int Delete(Expression<Func<T, bool>> where);

        int ExecuteSqlWithNonQuery(string sql, params object[] parameters);

        IList<TView> CustomQuery<TView>(string sql, params object[] parameters) where TView : class, new();


        /// <summary>
        /// 通用获取集合对象方法
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        //List<T> GetList(string sql, params object[] parameters);
        /// <summary>
        /// 以分页方式通用获取集合对象方法
        /// </summary>
        /// <param name="sql">查询的Sql语句</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="parameters">参数列表，如果没有则为null</param>
        /// <returns></returns>
        //List<T> GetList(string sql, int pageIndex, int pageSize, params object[] parameters);

        /// <summary>
        /// 执行sql语句查询返回DataTable
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        MicroDataTable ExecuteDataTable(string sql, params object[] parameters);

        /// <summary>
        /// 执行sql语句查询返回DataTable（实现分页） 
        /// </summary>
        /// <param name="sql">Sql语句</param>
        /// <param name="pageIndex">显示数量</param>
        /// <param name="pageSize">页码</param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        MicroDataTable ExecuteDataTable(string sql, int pageIndex, int pageSize, params object[] parameters);
        
    }
}